package cqrtplm.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class RequestParamHolder {
    private static final ThreadLocal<Map<String, Object>> context = new ThreadLocal<>();

    public static void put(String key, Object value) {
        Map<String, Object> map = context.get();
        if (map == null) {
            map = new HashMap<>();
            context.set(map);
        }
        map.put(key, value);
    }

    public static Object get(String key) {
        Map<String, Object> map = context.get();
        return map != null ? map.get(key) : null;
    }
    
    public static Long getLong(String key) {
        Object value = get(key);
        return value != null ? Long.valueOf(value.toString()) : null;
    }
    
    public static String getString(String key) {
        Object value = get(key);
        return value != null ? value.toString() : null;
    }

    public static void clear() {
        context.remove();
    }
}